package thread;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;

public class ThreadDemo24 {
    public static void main(String[] args) {
        BlockingQueue<String> queue = new ArrayBlockingQueue<>(1000);

        Thread t1 = new Thread(() -> {
            int n = 1;
           while(true){
               try {
                   queue.put(n + "");
                   System.out.println(n + " 入队列");
                   //Thread.sleep(500);
                   n++;
               } catch (InterruptedException e) {
                   throw new RuntimeException(e);
               }
           }
        });

        Thread t2 = new Thread(() -> {
            while(true){
                try {
                    String s = queue.take();
                    System.out.println(s + " 出队列");
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }
        });

        t1.start();
        t2.start();
    }
}
